package com.hundsun.cprs.yyt.gateway.service.uc.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.hundsun.cprs.yyt.gateway.enums.EnumFundBankNo;
import com.hundsun.cprs.yyt.gateway.request.*;
import com.hundsun.cprs.yyt.gateway.request.LJYSHRequest;
import com.hundsun.cprs.yyt.gateway.response.*;
import com.hundsun.cprs.yyt.gateway.response.LJYSHResponse;
import com.hundsun.cprs.yyt.gateway.vo.*;
import com.hundsun.cprs.yyt.gateway.response.*;
import com.hundsun.cprs.yyt.gateway.vo.UserRealNameInfo;
import com.hundsun.cprs.yyt.service.common.dto.*;
import com.hundsun.cprs.yyt.service.common.enums.*;
import com.hundsun.cprs.yyt.service.common.service.RemoteBrokerService;
import com.hundsun.cprs.yyt.util.StringUtil;
import com.hundsun.cprs.yyt.gateway.enums.EnumFundOutIn;
import com.hundsun.cprs.yyt.gateway.request.*;
import com.hundsun.cprs.yyt.gateway.service.BaseService;
import com.hundsun.cprs.yyt.gateway.service.uc.BankBindingFactory;
import com.hundsun.cprs.yyt.gateway.service.uc.BankBindingService;
import com.hundsun.cprs.yyt.gateway.vo.*;
import com.hundsun.network.common.exception.BusinessException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import com.alibaba.fastjson.JSON;
import com.hundsun.cprs.yyt.common.enums.EnumBusinessCode;
import com.hundsun.cprs.yyt.common.enums.EnumCommonCode;
import com.hundsun.cprs.yyt.common.exception.ServiceCodeException;
import com.hundsun.cprs.yyt.gateway.service.uc.UcCommonService;
import com.hundsun.cprs.yyt.gateway.vo.BankChannelInfoVo;
import com.hundsun.cprs.yyt.gateway.vo.BankClientInfo;
import com.hundsun.cprs.yyt.gateway.vo.BankFundAccountLog;
import com.hundsun.cprs.yyt.gateway.vo.BankInfoVo;
import com.hundsun.cprs.yyt.gateway.vo.UserVo;
import com.hundsun.cprs.yyt.service.common.service.RemoteTradeFundService;
import com.hundsun.cprs.yyt.service.common.service.RemoteUserService;
import com.hundsun.cprs.yyt.service.common.service.config.FundBankConfig;
import com.hundsun.cprs.yyt.util.BeanUtils;
import com.hundsun.cprs.yyt.util.ValueUtils;

@Service
public class UcCommonServiceImpl extends BaseService implements UcCommonService {
	
	@Autowired
	private RemoteUserService remoteUserService;
	
	@Autowired
	private RemoteTradeFundService remoteTradeFundService;
	
	@Autowired
	private FundBankConfig config;
	
	@Autowired
	private BankBindingFactory bankBindingFactory;

	@Autowired
	private RemoteBrokerService remoteBrokerService;


	@Override
	public LoginResponse login(LoginRequest request) {
		LoginResponse response = new LoginResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notEmpty(request.getAccount(),"登录账号必填");
			Validate.notEmpty(request.getPassword(),"登录密码必填");
			UserAccountDTO userInfo;
			if (StringUtil.equals(request.getIsEncrypt(), "1")) {
				userInfo = remoteUserService.encryptLogin(request.getAccount(), request.getPassword(), request.getLoginIp(), request.getBizType());
			} else {
				userInfo = remoteUserService.login(request.getAccount(), request.getPassword(), request.getLoginIp(), request.getBizType());
			}
			response.setUserId(userInfo.getId());
			response.setSessionToken(userInfo.getSessionToken());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());			
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public RegisterResponse register(RegisterRequest request) {
		if(logger.isInfoEnabled()){
			logger.info(ToStringBuilder.reflectionToString(request));
		}
		RegisterResponse response = new RegisterResponse();
		try {
			Validate.notNull(request,"参数非法");
//			Validate.notNull(request.getUcAccount(), "账号必填");
			Validate.notEmpty(request.getAccount(),"登录账号必填");
			Validate.notEmpty(request.getPassword(),"登录密码必填");
			Validate.notEmpty(request.getValidCode(),"注册校验码必填");
			Validate.notNull(request.getUserType(), "用户类型必填");
			//账号唯一性校验，UC接口未提供账号唯一性校验-.-!
			boolean isExist = remoteUserService.checkUniqueOfPhone(null, request.getAccount());
//			boolean isAccountExist = remoteUserService.checkUniqueOfAccount(null, request.getUcAccount());
			if(!isExist){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1013.getErrorNo(),"手机号码已被注册.");
			}
			/*if (!isAccountExist) {
			    throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1013.getErrorNo(), "账号已被注册.");
            }*/
            if (EnumUserType.indexByValue(request.getUserType()) == null) {
			    throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1020.getErrorNo(), "用户类型不正确.");
            }
			remoteUserService.register(BeanUtils.transfrom(UserRegisterInfo.class, request));
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse sendSmsCode(String phone) {
		BaseResponse response = new BaseResponse();
		try {
			Validate.notEmpty(phone,"手机号码必填");
			remoteUserService.sendRegCheckCode(phone);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}
	
	@Override
	public UserResposne getDetailOfUser(Long userId) {
		UserResposne response = new UserResposne();
		try{
			Validate.notNull(userId,"会员信息必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
			FundOpenStatus fundStatus = remoteTradeFundService.getFundAccountStatus(userId);
			UserVo userVo = new UserVo();
			userVo.setId(userInfo.getId());
			userVo.setPhone(userInfo.getPhone());
			userVo.setUserName(StringUtils.isEmpty(userInfo.getNickName())?userInfo.getName():userInfo.getNickName());
			userVo.setStatus(userInfo.getStatus());
			userVo.setStatusDesc(userInfo.getStatusDesc());
			userVo.setHeadimgUrl(userInfo.getHeadImgUrl());
			userVo.setGender(userInfo.getGender());
			userVo.setEmail(userInfo.getEmail());
			userVo.setRemark(userInfo.getRemak());
			userVo.setOpenFlag(fundStatus == null?0:fundStatus.isOpened()?1:fundStatus.isSigning()?2:0);
			userVo.setAge(userInfo.getAge());
			userVo.setFundAccount(userInfo.getFundAccount());
			userVo.setMcthLevel(userInfo.getMchtLevel());
			userVo.setFr(userInfo.getFr());
			userVo.setCertFrontImgUrl(userInfo.getCertFrontImgUrl());
			userVo.setCertReverseImgUrl(userInfo.getCertReverseImgUrl());
			userVo.setAuditRemark(userInfo.getAuditRemark());
			userVo.setIntegral(userInfo.getIntegral());
			userVo.setAccount(userInfo.getAccount());
			//转用户类型
			if (userInfo.getPartCategories1().equals(EnumUserType.INDIVIDUAL.getMapCode())){
				userVo.setUserType(EnumUserType.INDIVIDUAL.getType());
			}else{
				userVo.setUserType(EnumUserType.COMPANY.getType());
			}
			//加载资金账号信息
			FundBankAccountInfo accountInfo = remoteTradeFundService.getBankAccountDetailByFundAccount(userInfo.getFundAccount());
			if(userVo.getOpenFlag() > 0){
                userVo.setBankNo(accountInfo.getBankNo());
			    userVo.setBankProCode(accountInfo.getBankProCode());
			    //联交运上海银行所需
			    userVo.setBankBranch(accountInfo.getBankBranch());
			    userVo.setBankClientNo(accountInfo.getBankClientNo());
			    userVo.setChannelBankNo(accountInfo.getChannelBankNo());
            }
            if (accountInfo != null){
				userVo.setTaxRegisNum(accountInfo.getTaxRegisNum());
			}
			response.setResult(userVo);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public LoginInfoResponse getEncryptLoginInfo(Long userId) {
		LoginInfoResponse response = new LoginInfoResponse();
		try{
			Validate.notNull(userId,"会员信息必填");
			UserLoginInfoEncryptDto encryptDto = remoteUserService.encryptLoginInfo(userId);
			if (encryptDto == null) {
				throw new BusinessException(EnumBusinessCode.BUSINESS_3204.getErrorNo(), EnumBusinessCode.BUSINESS_3204.getErrorInfo());
			}
			response.setUserId(encryptDto.getUserId());
			response.setEncryptUserAccount(encryptDto.getEncryptUserAccount());
			response.setEncryptPassword(encryptDto.getEncryptPassword());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public UserResposne getBasicOfUser(Long userId) {
		UserResposne response = new UserResposne();
		try{
			Validate.notNull(userId,"会员信息必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailFromCacheByUserId(userId);
			if (userInfo == null){
				throw new ServiceCodeException("=====会员不存在=====");
			}
			UserVo userVo = new UserVo();
			userVo.setId(userInfo.getId());
			userVo.setUserName(StringUtils.isEmpty(userInfo.getNickName())?userInfo.getName():userInfo.getNickName());
			userVo.setHeadimgUrl(userInfo.getHeadImgUrl());
			response.setResult(userVo);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse modifyUser(UserRequest request) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getUserId(),"用户信息非法");
			UserAccountDTO modifyUserInfo = new UserAccountDTO();
			modifyUserInfo.setId(request.getUserId());
			modifyUserInfo.setNickName(request.getUserName());
			modifyUserInfo.setHeadImgUrl(request.getHeadimgUrl());
			modifyUserInfo.setGender(request.getGender());
			modifyUserInfo.setEmail(request.getEmail());
			modifyUserInfo.setRemak(request.getRemark());
			modifyUserInfo.setAge(request.getAge());
			remoteUserService.modifyUser(modifyUserInfo);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}
	
	@Override
	public BaseResponse realNameVerfiy(RealNameVerfiyRequest request) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getUserId(),"用户信息必填");
			Validate.notEmpty(request.getRealName(),"真实姓名必填");
			Validate.notEmpty(request.getCertNo(),"证件号码必填");
			Validate.notEmpty(request.getCertType(),"证件类型必填");
			//查询用户信息
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
			if(userInfo == null){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			}
			//判断是否已经开户
			boolean isOpenFlag = remoteTradeFundService.checkFundAccountStatus(request.getUserId());
			if(isOpenFlag){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1010.getErrorNo(),"资金账户已开户");
			}
			
			//组装请求信息
			UserAccountDTO newUserInfo = new UserAccountDTO();
			newUserInfo.setId(request.getUserId());
			newUserInfo.setName(request.getRealName());
			newUserInfo.setUserType(request.getUserType());
			newUserInfo.setCertificateType(request.getCertType());
			newUserInfo.setCertificateNum(request.getCertNo());
			newUserInfo.setFundPassword(request.getPayPwd());
			newUserInfo.setCertFrontImgUrl(request.getCertFrontImgUrl());
			newUserInfo.setCertReverseImgUrl(request.getCertReverseImgUrl());
			//会员是否已经实名过
			if(userInfo.isRealName()){
				//是则编辑信息
				//是否审核失败过
				if (userInfo.isAuditFail())
					newUserInfo.setStatus("2");//更改为待审核提交
				remoteUserService.modifyUser(newUserInfo);
			}else{
				//否则实名认证
				remoteUserService.realNameVerify(newUserInfo);
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse bindBank(RealNameVerfiyRequest request) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getUserId(),"用户信息必填");
			Validate.notEmpty(request.getBankAccount(),"银行卡号必填");
			//多渠道首先修改信息
			if (this.remoteTradeFundService.isMultichannel()){
				UserAccountDTO newUserInfo = new UserAccountDTO();
				newUserInfo.setId(request.getUserId());
				newUserInfo.setName(request.getRealName());
				newUserInfo.setBank(ValueUtils.getDefaultValue(request.getBankProCode(), this.config.getBankProCode()));
				newUserInfo.setBankCard(request.getBankAccount());
				this.remoteUserService.modifyUser(newUserInfo);
			}
			//再获取一次会员修改后的全量信息
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
			if(userInfo == null){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			}
			//实名和绑卡拆分为两个接口
			String bankNo = ValueUtils.getDefaultValue(request.getBankNo(), config.getBankNo());
			//资金开户
			FundOpenInfo openInfo = new FundOpenInfo();
			openInfo.setBankClientNo(request.getBankClientNo());
			openInfo.setBankAccount(request.getBankAccount());
			openInfo.setCertNo(userInfo.getCertificateNum());
			openInfo.setCertType(userInfo.getCertificateType());
			openInfo.setFundAccount(userInfo.getFundAccount());
			openInfo.setUserId(userInfo.getId());
			openInfo.setBankNo(bankNo);
			openInfo.setBankAccountName(StringUtil.isEmpty(request.getRealName()) ? userInfo.getName() : request.getRealName());
			openInfo.setBankProCode(ValueUtils.getDefaultValue(request.getBankProCode(), config.getBankProCode()));
			openInfo.setChannelBankNo(ValueUtils.getDefaultValue(request.getBankChannelNo(), config.getChannelBankNo()));
			//openInfo.setProcessType(config.getProcessType());
			openInfo.setMobile(request.getPhone());
			openInfo.setBankBranch(request.getBankBranch());//联交运上海银行必填
			openInfo.setBizNo(request.getBizNo());
			openInfo.setYzmxh(request.getYzmxh());
			openInfo.setDxyzm(request.getDxyzm());
			//获取银行渠道绑卡处理器
			BankBindingService bankBindingService = bankBindingFactory.getBankBindingService(bankNo);
			if(bankBindingService == null){
			    throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1000.getErrorNo(),"不支持[" + bankNo + "]的支付方式");
			}
			//开户校验
			bankBindingService.bindingValidate(openInfo,response);

		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
    public RealNameResponse realNameVerfiyInSecondStep(RealNameVerfiyRequest request) {
        RealNameResponse response = new RealNameResponse();
        try{
            Validate.notNull(request,"参数非法");
            Validate.notNull(request.getUserId(),"用户信息必填");
            Validate.notNull(request.getBankNo(),"支付方式必填");
            //Validate.notEmpty(request.getVerifiedCode(),"验证码必填");
            //查询用户信息
            UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
            if(userInfo == null){
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
            }
            //判断是否已经开户
			if (!remoteTradeFundService.isMultichannel()) {
				boolean isOpenFlag = remoteTradeFundService.checkFundAccountStatus(request.getUserId());
				if(isOpenFlag){
					throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1010.getErrorNo(),"资金账户已开户");
				}
			}
            
            //获取到资金账号的预开户信息
            FundBankAccountInfo fundAccoutnInfo = remoteTradeFundService.getBankAccountDetailByFundAccount(userInfo.getFundAccount());
            
            logger.info("预开户信息:" + JSON.toJSONString(fundAccoutnInfo));
            
            //资金开户
            FundOpenInfo openInfo = new FundOpenInfo();
            openInfo.setBankClientNo(request.getBankClientNo());
            openInfo.setBankAccount(userInfo.getBankCard());
            openInfo.setCertNo(userInfo.getCertificateNum());
            openInfo.setCertType(userInfo.getCertificateType());
            openInfo.setFundAccount(userInfo.getFundAccount());
            openInfo.setUserId(userInfo.getId());
            openInfo.setBankNo(request.getBankNo());
            openInfo.setBankAccountName(userInfo.getName());
            openInfo.setBankProCode(request.getBankProCode());
            openInfo.setChannelBankNo(request.getBankChannelNo());
            //openInfo.setProcessType(config.getProcessType());
            openInfo.setVerifiedCode(request.getVerifiedCode());
            openInfo.setCallbackUrl(request.getCallbackUrl());
            
            //获取银行渠道绑卡处理器
            BankBindingService bankBindingService = bankBindingFactory.getBankBindingService(request.getBankNo());
            if(bankBindingService == null){
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1000.getErrorNo(),"不支持[" + request.getBankNo() + "]的支付方式");
            }
            //开户
            bankBindingService.binding(openInfo,response);
            
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

	@Override
	public BaseResponse unBindBank(BankFundCloseRequest request) {
		RealNameResponse response = new RealNameResponse();
		try {
			Validate.notNull(request, "参数非法");
			Validate.notNull(request.getUserId(),"用户信息必填");
			Validate.notNull(request.getBankNo(), "支付方式必填");
			Validate.notNull(request.getBankProCode(), "银行产品代码必填");
			Validate.notNull(request.getChannelBankNo(), "银行编号必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
			if(userInfo == null){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			}

			//组装请求信息
			FundCloseInfo fundCloseInfo = new FundCloseInfo();
			fundCloseInfo.setUserId(request.getUserId());
			fundCloseInfo.setFundAccount(userInfo.getFundAccount());
			fundCloseInfo.setBankNo(request.getBankNo());
			fundCloseInfo.setBankProCode(request.getBankProCode());
			fundCloseInfo.setChannelBankNo(request.getChannelBankNo());
			//获取银行渠道绑卡处理器
			BankBindingService bankBindingService = bankBindingFactory.getBankBindingService(request.getBankNo());
			if(bankBindingService == null){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1000.getErrorNo(),"不支持[" + request.getBankNo() + "]的支付方式");
			}
			//解绑
			bankBindingService.unBinding(fundCloseInfo, response);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankFundOutInMemoResponse bankMemo(BankFundOutInMemoRequest request) {
		BankFundOutInMemoResponse response = new BankFundOutInMemoResponse();

		try {
			Validate.notNull(request, "参数非法");
			Validate.notNull(request.getAction(), "操作类型必填");
			Validate.notNull(request.getBankProCode(), "银行产品代码必填");
			EnumFundOutIn fundAction = EnumFundOutIn.index(request.getAction());
			Validate.isTrue(fundAction != null,"操作类型不支持");

			String memo = remoteTradeFundService.getFundMemo(fundAction.getCode(), request.getBankProCode());
			response.setMemo(memo);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankFundOutInApplyResponse bankApply(BankFundOutInApplyRequest request) {
		BankFundOutInApplyResponse response = new BankFundOutInApplyResponse();
		try {
			Validate.notNull(request,"参数必填");
			Validate.notNull(request.getUserId(),"用户信息必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			if (userInfo.getFundAccount() == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1003.getErrorNo(), EnumBusinessCode.BUSINESS_1003.getErrorInfo());
			BankFundOutInApplyQuery query = new BankFundOutInApplyQuery();
			query.setUserId(request.getUserId());
			query.setFundAccount(userInfo.getFundAccount());
			query.setStartDate(request.getStartDate());
			query.setEndDate(request.getEndDate());
			query.setStatus(request.getStatus());
			query.setPageSize(request.getPageSize());
			query.setPageNo(request.getPageNo());
			query.setTotalItem(request.getTotalItem() == null ? 0 : request.getTotalItem());
			FundBankOutInApplyResponse result = remoteTradeFundService.getFundApply(query);
			if(result != null && result.getTotalCount() > 0){
				response.setTotalCount(result.getTotalCount());
				response.setResult(BeanUtils.batchTransform(BankFundOutInApplyVo.class, result.getData(),BeanUtils.UNDERLYING_APACHE));
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
    public BaseResponse bindBankCard(RealNameVerfiyRequest request) {
        BaseResponse response = new BaseResponse();
        try{
            Validate.notNull(request,"参数非法");
            Validate.notNull(request.getUserId(),"用户信息必填");
            Validate.notEmpty(request.getRealName(),"真实姓名必填");
            Validate.notEmpty(request.getBankAccount(),"绑定账号必填");
            
            //查询用户信息
            UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
            if(userInfo == null){
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
            }
            
            //组装请求信息
            UserAccountDTO newUserInfo = new UserAccountDTO();
            newUserInfo.setId(request.getUserId());
            newUserInfo.setName(request.getRealName());
            newUserInfo.setBankCard(request.getBankAccount());
            
            remoteUserService.modifyUser(newUserInfo);
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

	@Override
	public BaseResponse modifyLoginPwd(Long userId, String password, String newPassword) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(userId,"参数非法");
			Validate.notEmpty(password,"[password] 参数必填");
			Validate.notEmpty(newPassword,"[newPassword] 参数必填");
			if(password.equals(newPassword))
				throw new IllegalArgumentException("新老密码必须不同");
			remoteUserService.modifyLoginPwd(userId, password, newPassword,EnumUserPwdType.LOGIN_PWD.getCode());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public ForgetResponse forgetPwd(String phone,String bizType) {
		ForgetResponse response = new ForgetResponse();
		try{
			Validate.notEmpty(phone,"参数非法");
            Validate.notEmpty(bizType,"业务类型必填");
            //查询该手机号码所属的会员
			UserAccountDTO userInfo = remoteUserService.getUserDetailByPhone(phone);
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),"用户名错误");
			remoteUserService.sendCheckCode(userInfo.getId(), bizType);
			//返回查询到用户信息
			response.setUserId(userInfo.getId());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse verifyForgetCode(Long userId, String code,String bizType) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notEmpty(code,"请发送验证码");
			Validate.notNull(userId,"短信验证码错误");
            Validate.notNull(bizType,"业务类型必填");
            //查询该手机号码所属的会员
			remoteUserService.verfiyCheckCode(userId, bizType, code);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}
	

	@Override
	public BaseResponse resetLoginPwd(Long userId, String code, String newPwd,String pwdType) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(userId,"会员ID必填");
			Validate.notEmpty(code,"验证码必填");
			Validate.notEmpty(newPwd,"重置密码必填");
            Validate.notEmpty(pwdType,"密码类型必填");
            remoteUserService.resetPwdByForget(userId, newPwd, code,pwdType);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public FundMoneyResponse getFundMoneyByUserId(Long userId) {
		FundMoneyResponse response = new FundMoneyResponse();
		try{
			Validate.notNull(userId,"参数非法");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			FundMoneyInfo fundMoneyInfo = remoteTradeFundService.getFundMoneyInfoByFundAccount(userInfo.getFundAccount());
			if(fundMoneyInfo == null){
				response.setCurrentBalance(0l);
				response.setFrozenBalance(0l);
				response.setCanGetBalance(0l);
				response.setCanUseBalance(0l);
			}else{
				response.setCurrentBalance(fundMoneyInfo.getCurrentBalance());
				response.setFrozenBalance(fundMoneyInfo.getFrozenBalance());
				response.setCanGetBalance(fundMoneyInfo.getCanGetBalance());
				response.setCanUseBalance(fundMoneyInfo.getCanUseBalance());
			}
			
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankFundOutInResponse fundOutIn(BankFundOutInRequest request) {
		BankFundOutInResponse response = new BankFundOutInResponse();
		try{
			Validate.notNull(request.getUserId(),"会员信息必填");
			Validate.notNull(request.getAmount(),"操作金额必填");
			Validate.isTrue(request.getAmount() > 0,"操作金额非法");
			Validate.notEmpty(request.getAction(),"操作类型必填");
			EnumFundOutIn fundAction = EnumFundOutIn.index(request.getAction());
			Validate.isTrue(fundAction != null,"操作类型不支持");
			if (StringUtil.equals(request.getBankNo(), EnumFundBankNo.OFLBHK.getCode()) && StringUtil.isEmpty(request.getMemo())) {
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_3020.getErrorNo(), EnumBusinessCode.BUSINESS_3020.getErrorInfo());
			}
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			if(StringUtils.isEmpty(userInfo.getFundAccount()))
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1003.getErrorNo(),"未绑定银行卡");
			if (!remoteTradeFundService.isMultichannel()) {//单渠道模式下需要从资金系统中拉取资金渠道信息
				FundBankAccountInfo fundInfo = remoteTradeFundService.getBankAccountDetailByFundAccount(userInfo.getFundAccount());
				request.setBankNo(fundInfo.getBankNo());
				request.setBankProCode(fundInfo.getBankProCode());
				request.setChannelBankNo(request.getChannelBankNo()==null?fundInfo.getChannelBankNo():request.getChannelBankNo());
			}
			FundCommResponse resp = null;
			if(fundAction == EnumFundOutIn.OUT){
				//Validate.notEmpty(request.getPayPwd(),"支付密码必填");
			    
				FundOutInRequest req = new FundOutInRequest();
				//多渠道下出金必填项start
				req.setBankNo(request.getBankNo());
				req.setBankProCode(request.getBankProCode());
				req.setChannelBankNo(request.getChannelBankNo());
				//多渠道下出金必填项end
				req.setFundAccount(userInfo.getFundAccount());
				req.setAmount(request.getAmount().longValue());
				//支付密码交给资金系统校验
				req.setPayPwd(request.getPayPwd());
				req.setUserId(userInfo.getId());
				req.setCallbackUrl(request.getCallbackUrl());
				//微信入金字段
				req.setOpenId(request.getOpenId());
				req.setCurrentLoginIp(request.getCurrentLoginIp());
				req.setMemo(request.getMemo());
				resp = remoteTradeFundService.fundOut(req);
			}
			if(fundAction == EnumFundOutIn.IN){
				//Validate.notEmpty(validCode,"验证码必填");
				FundOutInRequest req = new FundOutInRequest();
				//多渠道下入金必填项start
				req.setBankNo(request.getBankNo());
				req.setBankProCode(request.getBankProCode());
				req.setChannelBankNo(request.getChannelBankNo());
				//多渠道下入金必填项end
				req.setFundAccount(userInfo.getFundAccount());
				req.setAmount(request.getAmount().longValue());
				req.setValidCode(request.getValidCode());
				req.setUserId(userInfo.getId());
				req.setBizNo(request.getBizNo());
				req.setYzmxh(request.getYzmxh());
				req.setCallbackUrl(request.getCallbackUrl());
				req.setBankProTerminal(request.getBankProTerminal());
				//微信入金字段
				req.setOpenId(request.getOpenId());
				req.setCurrentLoginIp(request.getCurrentLoginIp());
				req.setMemo(request.getMemo());
				//双乾支付入金字段
				req.setPayBank(request.getPayBank());
				//通联支付必填
				req.setBankAccount(request.getBankAccount());
				resp = remoteTradeFundService.fundIn(req);
			}
			
			if(resp != null){
			    response.setErrorNo(resp.getCode());
				response.setErrorInfo(resp.getDesc());
				response.setSuccess(resp.isSuccess());
				response.setRedirectUrl(resp.getAttachment());
				response.setRequestContent(resp.getAttachmentDetail());
			}
			
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankListResponse getBankInfoList(String action) {
		BankListResponse response = new BankListResponse();
		try{
		    String type = "";
		    if (StringUtil.isNotEmpty(action)) {
                EnumFundOutIn fundAction = EnumFundOutIn.index(action);
                Validate.isTrue(fundAction != null,"操作类型不支持");
                type = StringUtil.equals(fundAction.getCode(), EnumFundOutIn.IN.getCode()) ? "01" : "02";
            }
			List<FundBankInfo> bankList;
			if (remoteTradeFundService.isMultichannel()) {
				bankList = remoteTradeFundService.getMultiAvailableBankList(type);
			} else {
				bankList = remoteTradeFundService.getAvailableBankList();
			}
			response.setResult(BeanUtils.batchTransform(BankInfoVo.class, bankList));
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankClientInfoResponse getBankClientInfoList(BankClientInfoRequest request) {
		BankClientInfoResponse response = new BankClientInfoResponse();
		try{
			if (request.getBankProCode() != null && "sqpay".equals(request.getBankProCode())){
				//暂时兼容双乾支付获取渠道支持的银行列表的新接口
				Validate.notEmpty(request.getBankProCode(),"银行渠道编号必填");
				Validate.notEmpty(request.getInfoType(),"所属银行类型必填");
				getBankClientInfoListByNewInterface(request,response);
			}else {
				Validate.notEmpty(request.getUserType(), "账号类型必填");
				request.setBankProCode(ValueUtils.getDefaultValue(request.getBankProCode(), config.getBankProCode()));
				List<FundBankClientNo> bankList = remoteTradeFundService.getBankClientNoList(request.getUserType(), request.getBankProCode());
				if (CollectionUtils.isNotEmpty(bankList)) {
					response.setResult(BeanUtils.batchTransform(BankClientInfo.class, bankList));
				} else {
					//判断是否为模拟银行，若是则组装模拟银行列表，方便实名测试
					checkAndMockBankList(response);
				}
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	private void getBankClientInfoListByNewInterface(BankClientInfoRequest request,BankClientInfoResponse response){
		FundPaymentInfoRequest fundPaymentInfoRequest = BeanUtils.transfrom(FundPaymentInfoRequest.class,request);
		List<FundPaymentInfoResponse> fundPaymentInfoResponseList = remoteTradeFundService.getFundPaymentConfig(fundPaymentInfoRequest);
		List<BankClientInfo> result = new ArrayList<>();
		if (!fundPaymentInfoResponseList.isEmpty()){
			for (FundPaymentInfoResponse fundPaymentInfoResponse : fundPaymentInfoResponseList){
				BankClientInfo bankClientInfo = new BankClientInfo();
				bankClientInfo.setBankClientNo(fundPaymentInfoResponse.getInfoCode());
				bankClientInfo.setBankName(fundPaymentInfoResponse.getInfoValue());
				result.add(bankClientInfo);
			}
			response.setResult(result);
		}
	}

	private void checkAndMockBankList(BankClientInfoResponse response){
		/*if("9999".equals(config.getBankNo())){
			BankClientInfo mockBank = new BankClientInfo();
			mockBank.setBankClientNo("9999");
			mockBank.setBankName("模拟银行");
			response.setResult(Arrays.asList(mockBank));
		}*/
	}


	@Override
	public UserRealNameResposne getRealNameInfo(Long userId) {
		UserRealNameResposne response = new UserRealNameResposne();
		try{
			Validate.notNull(userId,"用户信息必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			if(StringUtils.isEmpty(userInfo.getFundAccount()))
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1003.getErrorNo(),EnumBusinessCode.BUSINESS_1003.getErrorInfo());
			//查询银行账号信息
			FundBankAccountInfo bankAccountInfo = remoteTradeFundService.getBankAccountDetailByFundAccount(userInfo.getFundAccount());
			
			UserRealNameInfo realNameInfo = new UserRealNameInfo();
			realNameInfo.setRealName(bankAccountInfo.getHolderName());
			realNameInfo.setBankAccount(bankAccountInfo.getBankAccount());
			if(StringUtils.isEmpty(bankAccountInfo.getBankClientNo()) && "9999".equals(bankAccountInfo.getBankNo()))
				realNameInfo.setBankClientNo(bankAccountInfo.getBankNo());
			else
				realNameInfo.setBankClientNo(bankAccountInfo.getBankClientNo());
			if(!StringUtils.isEmpty(userInfo.getCertificateType()))
				realNameInfo.setCertType(EnumUserCertTypeMap.getByUcCode(userInfo.getCertificateType()).getUcCode());
			else
				realNameInfo.setCertType(EnumUserCertTypeMap.P01.getUcCode());//实在没有默认为 身份证
			realNameInfo.setCertNo(userInfo.getCertificateNum());
			response.setResult(realNameInfo);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse modifyMobile(Long userId, String newPhone, String checkCode) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(userId,"用户信息必填");
			Validate.notEmpty(newPhone,"新手机号码必填");
			Validate.notEmpty(checkCode,"校验码必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
			if(userInfo == null){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			}
			if(!StringUtils.isEmpty(userInfo.getPhone()) && userInfo.getPhone().equals(newPhone)){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1000.getErrorNo(),"新老手机号码必须不同");
			}
			//校验新手机号码是否唯一
			boolean isExist = remoteUserService.checkUniqueOfPhone(userInfo.getId(), newPhone);
			if(!isExist){
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1013.getErrorNo(),"手机号码已存在");
			}
			//校验验证码
			remoteUserService.verfiyCheckCode(userId, EnumSmsBizType.BIZ_MODIFY_MOBILE.getType(), checkCode);
			//修改手机号码
			remoteUserService.modifyBindMobile(userId, newPhone);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse modifyPayPwd(Long userId, String oldPwd, String newPwd) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(userId,"用户信息必填");
			Validate.notEmpty(oldPwd,"旧密码必填");
			Validate.notEmpty(newPwd,"新密码必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			//修改手机号码
			remoteUserService.modifyLoginPwd(userId, oldPwd, newPwd,EnumUserPwdType.PAY_PWD.getCode());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse sendSmsCodeByModifyMobile(Long userId, String newPhone) {
		BaseResponse response = new BaseResponse();
		try{
			Validate.notNull(userId,"用户信息必填");
			Validate.notEmpty(new Object[]{newPhone},"新手机号码必填");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			if(newPhone.equals(userInfo.getPhone()))
				throw new IllegalArgumentException("新老手机号码必须不同");
			//手机号码是否唯一
			remoteUserService.checkUniqueOfPhone(userId, newPhone);
			//发送手机验证码
			remoteUserService.sendCheckCode(userId, EnumSmsBizType.BIZ_MODIFY_MOBILE.getType());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankVerifyMsgResponse sendVerifyMsgForFundIn(FundInSmsRequest request) {
		BankVerifyMsgResponse response = new BankVerifyMsgResponse();
		try{
			Validate.notNull(request.getUserId(),"用户信息必填");
			Validate.isTrue(request.getAmount()!=null&&request.getAmount() > 0,"充值金额必填且大于0");
			UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
			if(userInfo == null)
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
			if(StringUtils.isEmpty(userInfo.getFundAccount()))
				throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1003.getErrorNo(),"未绑定银行卡");
			FundBankChannelVerificateRequest req = new FundBankChannelVerificateRequest();
			req.setAmount(request.getAmount());
			req.setBankChannelNo(request.getChannelBankNo()==null?config.getChannelBankNo():request.getChannelBankNo());
			req.setFundAccount(userInfo.getFundAccount());
			req.setBankAccount(request.getBankAccount());
			req.setVerifyType("1");
			FundBankChannelVerificateInfo result = remoteTradeFundService.sendAndGetBankChannelVerificateCode(req);
			if(result != null){
				response.setBizNo(result.getBizNo());
				response.setYzmxh(result.getYzmxh());
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BankFundOutInConfigResponse getFundOutInConfigInfo(String bankProCode) {
		BankFundOutInConfigResponse response = new BankFundOutInConfigResponse();
		try{
		    bankProCode = ValueUtils.getDefaultValue(bankProCode, config.getBankProCode());
			Map<String,String> configMap = remoteTradeFundService.getConfigInfoByBankChannel(bankProCode);
			if(!configMap.isEmpty()){
				response.setFundInMin(Long.valueOf(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_IN_MIN.getKey(), "0")));
				response.setFundInRate(Double.valueOf(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_IN_RATE.getKey(), "0")));
				response.setFundOutFeeMin(Long.valueOf(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_OUT_FEE_MIN.getKey(), "0")));
				response.setFundOutFeeRate(Double.valueOf(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_OUT_FEE_RATE.getKey(), "0")));
				response.setFundOutFeeBegin(Double.valueOf(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_OUT_FEE_BEGIN.getKey(), "0")));
				response.setFundOutFeeFix(Double.valueOf(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_OUT_FEE_FIX.getKey(), "0")));
				response.setFundOutFeeMessage(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_OUT_FEE_MESSAGE.getKey(), ""));
                response.setFundOutFeeType(ValueUtils.getValueFromMap(configMap, EnumBankConfigKey.FUND_OUT_FEE_TYPE.getKey(), "A"));
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
    public UserResposne getDetailOfUserByPromotionCode(String fr) {
        UserResposne response = new UserResposne();
        try{
            Validate.notEmpty(fr,"会员推广码必填");
            UserAccountDTO userInfo = remoteUserService.getUserDetailByFr(fr);
            if (userInfo==null||userInfo.getId()==null){
            	throw new ServiceCodeException("会员推广码不存在");
			}
            boolean isOpenFlag = remoteTradeFundService.checkFundAccountStatus(userInfo.getId());
            UserVo userVo = new UserVo();
            userVo.setId(userInfo.getId());
            userVo.setPhone(userInfo.getPhone());
            userVo.setUserName(StringUtils.isEmpty(userInfo.getNickName())?userInfo.getName():userInfo.getNickName());
            userVo.setStatus(userInfo.getStatus());
            userVo.setStatusDesc(userInfo.getStatusDesc());
            userVo.setHeadimgUrl(userInfo.getHeadImgUrl());
            userVo.setGender(userInfo.getGender());
            userVo.setEmail(userInfo.getEmail());
            userVo.setRemark(userInfo.getRemak());
            userVo.setOpenFlag(isOpenFlag?1:0);
            userVo.setAge(userInfo.getAge());
            userVo.setFundAccount(userInfo.getFundAccount());
            userVo.setMcthLevel(userInfo.getMchtLevel());
            userVo.setFr(userInfo.getFr());
			userVo.setCertFrontImgUrl(userInfo.getCertFrontImgUrl());
			userVo.setCertReverseImgUrl(userInfo.getCertReverseImgUrl());
			userVo.setAuditRemark(userInfo.getAuditRemark());
            response.setResult(userVo);
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

    @Override
    public HeadImgUpdateResponse modifyUserHeadImg(Long userId, String headImgBase64) {
        HeadImgUpdateResponse response = new HeadImgUpdateResponse();
        try{
            Validate.notNull(userId,"用户信息必填");
            Validate.notEmpty(headImgBase64,"头像信息必填");
            UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(userId);
            if(userInfo == null)
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
            String headImgUrl = remoteUserService.updateHeadImgOfUser(userId, headImgBase64);
            response.setHeadimgUrl(headImgUrl);
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

    @Override
    public BaseResponse sendVerifyMsgForOpen(RealNameVerfiyRequest request) {
        BaseResponse response = new BaseResponse();
        try{
            Validate.notNull(request,"参数必填");
            Validate.notNull(request.getUserId(),"用户信息必填");
            Validate.notEmpty(request.getPhone(),"手机号码必填");
            UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
            if(userInfo == null)
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
            if(StringUtils.isEmpty(userInfo.getFundAccount()))
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1003.getErrorNo(),"未实名认证");
            
            //获取用户提交的银行账号信息
            FundBankAccountInfo bankInfo = remoteTradeFundService.getBankAccountDetailByFundAccount(userInfo.getFundAccount());
            
            FundBankChannelVerificateRequest req = new FundBankChannelVerificateRequest();
            req.setBankChannelNo(request.getBankChannelNo());
            req.setBankClientNo(request.getBankClientNo());
            req.setFundAccount(bankInfo.getFundAccount());
            req.setMobile(request.getPhone());
            req.setBankAccount(request.getBankAccount() != null ? request.getBankAccount() : bankInfo.getBankAccount());
            req.setVerifyType("0");
            remoteTradeFundService.sendAndGetBankChannelVerificateCode(req);
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

    @Override
    public BankFundAccountLogResponse getFundAccountLogList(BankFundAccountLogRequest request) {
        BankFundAccountLogResponse response = new BankFundAccountLogResponse();
        try{
            Validate.notNull(request,"参数必填");
            Validate.notNull(request.getUserId(),"用户信息必填");
            UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
            if(userInfo == null)
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
            FundAccountLogQuery query = new FundAccountLogQuery();
            query.setUserId(userInfo.getId());
            query.setPageSize(request.getPageSize());
            query.setPageNo(request.getPageNo());
            query.setStartDate(request.getStartDate());
            query.setEndDate(request.getEndDate());
            query.setTransCode(request.getTransCode());
            query.setQueryToday(request.getQueryHistory() == 1?false:true);
            FundAccountLogInfoResponse result = remoteTradeFundService.getFundAccountLogByPage(query);
            if(result != null && result.getTotalCount() > 0){
                response.setTotalCount(result.getTotalCount());
                response.setResult(BeanUtils.batchTransform(BankFundAccountLog.class, result.getData(),BeanUtils.UNDERLYING_APACHE));
            }
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

	@Override
	public ThirdLoginResponse validateBindStatusAndLogin(ThirdAccountRequest request) {
		ThirdLoginResponse response = new ThirdLoginResponse();
        try{
        	Validate.notNull(request,"参数必填");
            Validate.notNull(request.getUnionid(),"三方用户标识必填");
            Validate.notNull(request.getType(),"三方用户类型必填");
            ThirdLoginDTO thirdLoginDTO=remoteUserService.validateBindStatus(request.getUnionid(), request.getType());
            response.setStatus(thirdLoginDTO.getBindStatus());
            //如果是已绑定状态，则调登录接口
            if(thirdLoginDTO.getBindStatus()==1){
            	LoginRequest loginRequest = new LoginRequest();
            	loginRequest.setAccount(thirdLoginDTO.getUserAccountDTO().getAccount());
            	loginRequest.setPassword(thirdLoginDTO.getUserAccountDTO().getPassword());
            	LoginResponse loginResponse=this.login(loginRequest);
            	if(loginResponse.getErrorNo()!=0){
            		//登录失败，直接返回错误信息
            		response.setErrorNo(loginResponse.getErrorNo());
                    response.setErrorInfo(loginResponse.getErrorInfo());
                    return response;
            	}else{
            		//登录成功，返回用户信息
            		response.setUserId(loginResponse.getUserId());
            	}
            }
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
	}

	/*@Override
	public ThirdLoginResponse bindThirdAccountAndLogin(BindThirdAccountRequest request) {
		ThirdLoginResponse response = new ThirdLoginResponse();
        try{
        	Validate.notNull(request,"参数必填");
        	Validate.notNull(request.getAccount(),"登录账号必填");
            Validate.notNull(request.getPassword(),"登录密码必填");
            Validate.notNull(request.getUnionid(),"三方用户标识必填");
            Validate.notNull(request.getType(),"三方用户类型必填");
            UserAccountDTO userAccountDTO=remoteUserService.getUserDetailByUserAccount(request.getAccount());
            ThirdLoginDTO thirdLoginDTO=remoteUserService.bindThirdAccount(userAccountDTO.getId(), request.getUnionid(), request.getType());
            response.setStatus(thirdLoginDTO.getBindStatus());
            //如果绑定成功，则调登录接口
            if(thirdLoginDTO.getBindStatus()==1){
            	LoginRequest loginRequest = new LoginRequest();
            	loginRequest.setAccount(request.getAccount());
            	loginRequest.setPassword(request.getPassword());
            	LoginResponse loginResponse=this.login(loginRequest);
            	if(loginResponse.getErrorNo()!=0){
            		//登录失败，直接返回错误信息
            		response.setErrorNo(loginResponse.getErrorNo());
                    response.setErrorInfo(loginResponse.getErrorInfo());
                    return response;
            	}else{
            		//登录成功返回用户信息
            		response.setUserId(loginResponse.getUserId());
            	}
            }
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
	}*/

	@Override
	public ThirdLoginResponse validateAccountIsExist(BindThirdAccountRequest request) {
		ThirdLoginResponse response = new ThirdLoginResponse();
		try{
			Validate.notNull(request,"参数必填");
			Validate.notNull(request.getAccount(),"登录账号必填");
			Validate.notNull(request.getValidCode(),"验证码必填");
			Validate.notNull(request.getUnionid(),"三方用户标识必填");
			Validate.notNull(request.getType(),"三方用户类型必填");

			//1.校验系统是否存在该账号，调用会员提供的根据账号和验证码方式校验接口
			Map<String,String> resultMap = remoteUserService.validateAccount(request.getAccount(),request.getValidCode());
			if (resultMap.get("existFlag").equals("Y")){
				//2.账号存在，则直接将三方账号和系统账号绑定，并直接登录
				bindThirdAccountAndLogin(response,request);
			}else{
				//3.若账号不存在，则返回会员生成的token，前端进入注册绑定页面
				response.setStatus(2);//状态为2表示前端需要进入注册并绑定页面
				response.setSessionToken(resultMap.get("token"));
			}

		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public ThirdLoginResponse regAndBindThirdAccountLogin(RegAndBindThirdAccountRequest request) {
		ThirdLoginResponse response = new ThirdLoginResponse();
        try{
        	Validate.notNull(request,"参数必填");
        	Validate.notNull(request.getAccount(),"登录账号必填");
            Validate.notNull(request.getPassword(),"登录密码必填");
            Validate.notNull(request.getUnionid(),"三方用户标识必填");
            Validate.notNull(request.getType(),"三方用户类型必填");
            //Validate.notNull(request.getValidCode(),"验证码必填");
			Validate.notNull(request.getToken(),"注册token必填");
            //先注册
            RegisterRequest registerRequest=BeanUtils.transfrom(RegisterRequest.class, request);            
            RegisterResponse registerResponse=this.register(registerRequest);
            if(registerResponse.getErrorNo()!=0){
            	//注册失败直接返回错误信息
            	response.setErrorNo(registerResponse.getErrorNo());
            	response.setErrorInfo(registerResponse.getErrorInfo());
            }else{
            	//注册成功，再绑定登录
            	BindThirdAccountRequest bindThirdAccountRequest = BeanUtils.transfrom(BindThirdAccountRequest.class, request);            	
            	//response=this.bindThirdAccountAndLogin(bindThirdAccountRequest);
				bindThirdAccountAndLogin(response,bindThirdAccountRequest);
            }
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
	}

	/**
	 * 绑定三方账号并登录
	 * @param response
	 * @param request
	 * */
	protected void bindThirdAccountAndLogin(ThirdLoginResponse response,BindThirdAccountRequest request){
		UserAccountDTO userAccountDTO=remoteUserService.getUserDetailByUserAccount(request.getAccount());
		if (userAccountDTO == null){
			throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
		}
		ThirdLoginDTO thirdLoginDTO=remoteUserService.bindThirdAccount(userAccountDTO.getId(), request.getUnionid(), request.getType());
		response.setStatus(thirdLoginDTO.getBindStatus());
		//如果绑定成功，则调登录接口
		if(thirdLoginDTO.getBindStatus()==1){
			LoginRequest loginRequest = new LoginRequest();
			loginRequest.setAccount(thirdLoginDTO.getUserAccountDTO().getAccount());
			loginRequest.setPassword(thirdLoginDTO.getUserAccountDTO().getPassword());
			LoginResponse loginResponse=this.login(loginRequest);
			if(loginResponse.getErrorNo()!=0){
				//登录失败，直接返回错误信息
				response.setErrorNo(loginResponse.getErrorNo());
				response.setErrorInfo(loginResponse.getErrorInfo());
			}else{
				//登录成功返回用户信息
				response.setUserId(loginResponse.getUserId());
			}
		}
	}

    @Override
    public BankChannelListResponse getBankChannelListByBankProCode(String bankProCode) {
        BankChannelListResponse response = new BankChannelListResponse();
        try{
            Validate.notEmpty(bankProCode,"银行渠道代码必填");
            List<FundBankChannelInfo> result  = remoteTradeFundService.getBankChannelInfoByBankProCode(bankProCode);
            if(CollectionUtils.isNotEmpty(result)){
                response.setResult(BeanUtils.batchTransform(BankChannelInfoVo.class, result));
            }
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

    @Override
    public BankFundSignStatusResponse getBankFundSignStatus(BankFundSignStatusRequest request) {
        BankFundSignStatusResponse response = new BankFundSignStatusResponse();
        try {
            Validate.notNull(request,"参数必填");
            Validate.notNull(request.getUserId(),"用户信息必填");
            EnumFundOutIn fundAction = EnumFundOutIn.index(request.getAction());
            Validate.isTrue(fundAction != null,"操作类型不支持");
            //查询用户信息
            UserAccountDTO userInfo = remoteUserService.getUserDetailByUserId(request.getUserId());
            if(userInfo == null){
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1001.getErrorNo(),EnumBusinessCode.BUSINESS_1001.getErrorInfo());
            }
            String fundAccount = userInfo.getFundAccount();
            if (StringUtil.isEmpty(fundAccount)) {
                throw new ServiceCodeException(EnumBusinessCode.BUSINESS_1002.getErrorNo(), EnumBusinessCode.BUSINESS_1002.getErrorInfo());
            }
			boolean status = remoteTradeFundService.checkMultichannelSign(fundAccount, request.getChannelBankNo(), StringUtil.equals(EnumFundOutIn.IN.getCode(), request.getAction()) ? "01" : "02");
            response.setChannelStatus(status ? "2" : "1");//1:需要签约;2：不需要签约
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

    @Override
    public BankMultichannelStatusResponse getBankMultichannelStatus() {
        BankMultichannelStatusResponse response = new BankMultichannelStatusResponse();
        try {
            boolean status = remoteTradeFundService.isMultichannel();
            response.setStatus(status ? "2" : "1");
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

    @Override
    public ImgUploadResponse imgUpload(String imgBase64) {
	    ImgUploadResponse response = new ImgUploadResponse();
        try {
            Validate.notEmpty(imgBase64,"头像信息必填");
            String imgUrl = remoteUserService.uploadImg(imgBase64);
            response.setImgUrl(imgUrl);
        } catch (IllegalArgumentException e) {
            response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
            response.setErrorInfo(e.getMessage());
        } catch (ServiceCodeException e) {
            response.setErrorNo(e.getErrorCode());
            response.setErrorInfo(e.getErrorDesc());
        } catch (Exception e) {
            logger.error("处理异常",e);
            response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
            response.setErrorInfo(e.getMessage());
        }
        return response;
    }

	@Override
	public BankParamInfoResponse getBankParamInfoList(BankParamInfoRequest request) {
		BankParamInfoResponse response = new BankParamInfoResponse();
		try{
			Validate.notEmpty(request.getBankProCode(),"银行产品号必填");
			Validate.notEmpty(request.getKeyType(),"银行参数键值必填");
			request.setBankProCode(ValueUtils.getDefaultValue(request.getBankProCode(), config.getBankProCode()));
			List<FundBankParamInfo> bankList = remoteTradeFundService.getBankParamInfoList(request.getBankProCode(), request.getKeyType());
			if(CollectionUtils.isNotEmpty(bankList)){
				response.setBankParamInfoVoList(BeanUtils.batchTransform(BankParamInfoVo.class, bankList));
			}else{
				response.setBankParamInfoVoList(null);
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public FundPaymentConfigResponse getFundPaymentConfigList(FundPaymentConfigRequest request) {
		FundPaymentConfigResponse response = new FundPaymentConfigResponse();
		try{
			Validate.notEmpty(request.getChannelBankNo(),"银行渠道编号必填");
			Validate.notEmpty(request.getInfoType(),"所属银行类型必填");
			FundPaymentInfoRequest fundPaymentInfoRequest = BeanUtils.transfrom(FundPaymentInfoRequest.class,request);
			List<FundPaymentInfoResponse> fundPaymentInfoResponseList = remoteTradeFundService.getFundPaymentConfig(fundPaymentInfoRequest);
			List<FundPaymentConfigVo> fundPaymentConfigVoList = null;
			if (!fundPaymentInfoResponseList.isEmpty()){
				fundPaymentConfigVoList = BeanUtils.batchTransform(FundPaymentConfigVo.class,fundPaymentInfoResponseList);
			}
			response.setFundPaymentConfigVoList(fundPaymentConfigVoList);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getErrorDesc());
		} catch (Exception e) {
			logger.error("处理异常",e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(e.getMessage());
		}
		return response;
	}

	@Override
	public BaseResponse logout(LogoutRequest request) {
		BaseResponse response = new LoginResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notEmpty(request.getAccount(),"登录账号必填");
			Validate.notEmpty(request.getSessionToken(),"登录会话令牌必填");
			remoteUserService.logout(request.getAccount(), request.getSessionToken());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LJYSHResponse getBanks(LJYSHRequest request) {
		LJYSHResponse response = new LJYSHResponse();
		try {
			Validate.notNull(request,"参数非法");
			LJBankRequest ljBankRequest = new LJBankRequest();
			ljBankRequest.setBankType(request.getBankType());
			LJBankResponse ljBankResponse = remoteTradeFundService.getBanks(ljBankRequest);
			response.setResultObj(ljBankResponse.getResultObj());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LJYSHResponse getProveniences() {
		LJYSHResponse response = new LJYSHResponse();
		try {
			LJBankResponse ljBankResponse = remoteTradeFundService.getProveniences();
			response.setResultObj(ljBankResponse.getResultObj());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LJYSHResponse getCities(LJYSHRequest request) {
		LJYSHResponse response = new LJYSHResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getProvenienceCode(),"省编码必填");
			LJBankRequest ljBankRequest = new LJBankRequest();
			ljBankRequest.setProvenienceCode(request.getProvenienceCode());
			LJBankResponse ljBankResponse = remoteTradeFundService.getCities(ljBankRequest);
			response.setResultObj(ljBankResponse.getResultObj());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LJYSHResponse getAreas(LJYSHRequest request) {
		LJYSHResponse response = new LJYSHResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getCityCode(),"城市编码必填");
			LJBankRequest ljBankRequest = new LJBankRequest();
			ljBankRequest.setCityCode(request.getCityCode());
			LJBankResponse ljBankResponse = remoteTradeFundService.getAreas(ljBankRequest);
			response.setResultObj(ljBankResponse.getResultObj());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LJYSHResponse getBankBranchs(LJYSHRequest request) {
		LJYSHResponse response = new LJYSHResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getBankCode(),"银行编码必填");
			LJBankRequest ljBankRequest = new LJBankRequest();
			ljBankRequest.setBankCode(request.getBankCode());
			ljBankRequest.setProvenienceCode(request.getProvenienceCode());
			ljBankRequest.setCityCode(request.getCityCode());
			ljBankRequest.setAreaCode(request.getAreaCode());
			ljBankRequest.setKeywords(request.getKeyWords());
			LJBankResponse ljBankResponse = remoteTradeFundService.getBankBranchs(ljBankRequest);
			response.setResultObj(ljBankResponse.getResultObj());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LJYSHResponse getBankBranch(LJYSHRequest request) {
		LJYSHResponse response = new LJYSHResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getBankBranchCode(),"联行号必填");
			LJBankRequest ljBankRequest = new LJBankRequest();
			ljBankRequest.setBankBranchCode(request.getBankBranchCode());
			LJBankResponse ljBankResponse = remoteTradeFundService.getBankBranch(ljBankRequest);
			response.setResultObj(ljBankResponse.getResultObj());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public BrokerReferRelateResponse queryBrokerRelateList(BrokerReferRelateRequest request) {
		BrokerReferRelateResponse response = new BrokerReferRelateResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notNull(request.getUpUserId(),"用户信息必填");
			ReferRelateRequestDto requestDto = BeanUtils.transfrom(ReferRelateRequestDto.class,request);
			requestDto.setUpUserId(request.getUpUserId().toString());
			BrokerReferRelateInfo brokerReferRelateInfo = remoteBrokerService.queryBrokerRelateList(requestDto);
			if (brokerReferRelateInfo != null){
				response = BeanUtils.transfrom(BrokerReferRelateResponse.class,brokerReferRelateInfo);
				response.setUserReferRelateDtoList(BeanUtils.batchTransform(UserReferRelateVo.class,brokerReferRelateInfo.getUserReferRelateDtoList()));
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public LoginResponse tokenLogin(TokenLoginRequest request) {
		LoginResponse response = new LoginResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notEmpty(request.getSessionToken(),"会话token必填");
			UserAccountDTO userInfo;
			userInfo = remoteUserService.tokenLogin(request.getSessionToken(), request.getLoginIp());
			response.setUserId(userInfo.getId());
			response.setSessionToken(userInfo.getSessionToken());
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public BankAccountResponse getCanUserSignAccount(BankAccountRequest request) {
		BankAccountResponse response = new BankAccountResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notEmpty(request.getFundAccount(),"资金账号必填");
			Validate.notEmpty(request.getChannelBankNo(),"渠道银行编号必填");
			FundBankAccountRequest fundBankAccountRequest = BeanUtils.transfrom(FundBankAccountRequest.class,request);
			List<FundBankAccountDto> fundBankAccountDtos = remoteTradeFundService.getCanUserSignAccount(fundBankAccountRequest);
			if (CollectionUtils.isNotEmpty(fundBankAccountDtos)){
				response.setBankAccountVoList(BeanUtils.batchTransform(BankAccountVo.class,fundBankAccountDtos));
			}
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}

	@Override
	public BaseResponse cancelSignAccount(BankAccountRequest request) {
		BaseResponse response = new BaseResponse();
		try {
			Validate.notNull(request,"参数非法");
			Validate.notEmpty(request.getFundAccount(),"资金账号必填");
			Validate.notEmpty(request.getChannelBankNo(),"渠道银行编号必填");
			Validate.notEmpty(request.getBankAccount(),"银行账号必填");
			FundBankAccountRequest fundBankAccountRequest = BeanUtils.transfrom(FundBankAccountRequest.class,request);
			remoteTradeFundService.cancelSignAccount(fundBankAccountRequest);
		} catch (IllegalArgumentException e) {
			response.setErrorNo(EnumBusinessCode.BUSINESS_1000.getErrorNo());
			response.setErrorInfo(e.getMessage());
		} catch (ServiceCodeException e) {
			response.setErrorNo(e.getErrorCode());
			response.setErrorInfo(e.getMessage());
			response.setSuccess(false);
		} catch (Exception e) {
			logger.error(e);
			response.setErrorNo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorNo());
			response.setErrorInfo(EnumCommonCode.COMMON_SERVER_ERROR.getErrorInfo());
			response.setSuccess(false);
		}
		return response;
	}
}
